package edu.cmu.cs.stage3.alice.authoringtool.datatransfer;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources;

/**
 * @author Jason Pratt
 */
public class PropertyReferenceTransferable implements Transferable {

 public final static DataFlavor propertyReferenceFlavor = AuthoringToolResources.getReferenceFlavorForClass( edu.cmu.cs.stage3.alice.core.Property.class );

 protected DataFlavor[] flavors;
 protected edu.cmu.cs.stage3.alice.core.Property property;

 public PropertyReferenceTransferable( edu.cmu.cs.stage3.alice.core.Property property ) {
  this.property = property;

  flavors = new DataFlavor[2];
  flavors[0] = propertyReferenceFlavor;
  flavors[1] = DataFlavor.stringFlavor;  // bug work-around
 }

 public DataFlavor[] getTransferDataFlavors() {
  return flavors;
 }

 public boolean isDataFlavorSupported( DataFlavor flavor ) {
  //LOB for (DataFlavor flavor2 : flavors)
  DataFlavor [] flavor2 = flavors;
  int _tam = flavor2!=null ? flavor2.length : 0;
  for (int _i=0; _i<_tam; _i++)  { //L
   if( flavor.equals( flavor2[_i] ) ) { //L flavor.equals( flavor2 )
    return true;
   }
  }
  return false;
 }

 public Object getTransferData( DataFlavor flavor ) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException {
  if( flavor.equals( propertyReferenceFlavor ) ) {
   return property;
  } else if( flavor.equals( DataFlavor.stringFlavor ) ) {
   return property.toString();
  } else {
   throw new java.awt.datatransfer.UnsupportedFlavorException( flavor );
  }
 }

}
